import httpFetch from 'share/httpFetch'
import config from 'config'
import LoginService from 'containers/login/login.service';
import errorMessage from "share/errorMessage";
export default {
  //查看报表列表
  getLoginLogList(page, pageSize) {
    return httpFetch.get(`${config.baseUrl}/auth/api/userloginlog/my?page=${page}&size=${pageSize}`);
  },

  getEditMobileVerifiCode(mobile,countryCode) {
    return httpFetch.get(`${config.baseUrl}/api/refactor/update/mobile/token/v2?mobile=${mobile}`);
  },

  getEditEmailVerifiCode(email) {
    return httpFetch.get(`${config.baseUrl}/api/refactor/bind/email/token/v2?email=${email}`);
  },

  getVerifyMobileVerifiCode(mobile, attachmentOID, verifyCode){
    let time = (new Date()).getTime();
    return httpFetch.get(`${config.baseUrl}/api/refactor/validate/mobile/token/v3?time=${time}&mobile=${LoginService.enCodePassword(mobile)}&attachmentOID=${attachmentOID}&verifyCode=${verifyCode}&client=web`);
  },

  getBindMobileVerifiCode(mobile, id, code){
    let time = (new Date()).getTime();
    return httpFetch.get(`${config.baseUrl}/api/refactor/set/mobile/token/v3?time=${time}&mobile=${LoginService.enCodePassword(mobile)}&attachmentOID=${id}&verifyCode=${code}&client=web`);
  },

  checkToken(mobile,token){
    return httpFetch.post(`${config.baseUrl}/api/refactor/validate/mobile/token/check/v2?mobile=${mobile}&token=${token}`)
  },

  updateMobile(mobile,token) {
    return httpFetch.post(`${config.baseUrl}/api/refactor/update/mobile/finish/v2?mobile=${mobile}&token=${token}`)
  },

  updateEmail(email,token) {
    return httpFetch.post(`${config.baseUrl}/api/refactor/bind/change/email/v2?email=${email}&token=${token}`)
  },

  verifyMobile(mobile,token) {
    let params = {
      mobile: LoginService.enCodePassword(mobile),
      token,
      client: "web"
    };
    return httpFetch.post(`${config.baseUrl}/api/refactor/validate/mobile/finish/v3`, params)
  },

  bindMobile(mobile,token,countryCode) {
    let params = {
      client: "web",
      mobile: LoginService.enCodePassword(mobile),
      countryCode: "",
      token,
    };
    return httpFetch.post(`${config.baseUrl}/api/refactor/set/mobile/finish/v3`, params)
  },
  modifyPassword(oldPassword, newPassword){
    let params = {
      client: "web",
      oldPassword: LoginService.enCodePassword((oldPassword)),
      newPassword: LoginService.enCodePassword((newPassword)),
    };
    return httpFetch.post(`${config.baseUrl}/api/refactor/account/change_password/v3`, params)
  },
  /**
   * @returns {*}
   * not.set 未设置
   * not.validate 设置未验证
   * activated 已验证
   */
  getMobileStatus() {
    return httpFetch.get(`${config.baseUrl}/api/refactor/mobile/status`);
  },

  //获取短信验证码
  getMobileEmailVerifyCode(login, countryCode, attachmentOID, verifyCode) {
    return new Promise((resolve, reject) => {
      let params = {
        client: "web",
        login: LoginService.enCodePassword(login),
        countryCode: "",
        attachmentOID,
        verifyCode,
      };
      let time = (new Date()).getTime();
      httpFetch.get(`${config.baseUrl}/api/refactor/update/mobile/token/v3?time=${time}`, params)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },

  //验证账号和短信验证码
  identityMobileEmailVerifyCode(login, token) {
    let params = {
      client: "web",
      login: LoginService.enCodePassword(login),
      countryCode: "",
      token,
    };
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.baseUrl}/api/refactor/update/mobile/finish/v3`, params)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
}
